# -*- coding: utf-8 -*-

from django.db.models import F
from django.shortcuts import render

from .. import models

def home(request):  # 首页
    pj_name = models.Project_Data.objects.all().values()
    interface_num = models.Interface_Data.objects.all().values()
    pjNameList = []
    pj_id_num = []
    pj_interface_num = []
    result = []
    for i in pj_name:
        for key1, value1 in i.items():
            if key1 == 'pj_name':
                pjNameList.append(value1)
            if key1 == 'id':
                pj_id_num.append(value1)
    for j in pj_id_num:  # 判断项目id和接口status对应的有多少条用例
        pj_interface_num.append(models.Interface_Data.objects.filter(status=j).count())
        result.append(models.Interface_Data.objects.filter(status=j, in_expected_result=F('in_actual_result')).count())
    return render(request, 'Page/Home.html',
                  {'pjNameList': pjNameList, 'pj_interface_num': pj_interface_num, 'result': result})
